package com.ugrow.ugrowcommunity.vm.forum.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.ugrow.ugrowcommunity.R;

import com.ugrow.ugrowcommunity.activity.courseselection.bean.Data;
import com.ugrow.ugrowcommunity.databinding.CourseSelectionItemBinding;
import com.ugrow.ugrowcommunity.databinding.RecruitItemLayoutBinding;
import com.ugrow.ugrowcommunity.vm.forum.bean.RecruitBean;

import java.util.List;

public class RecruitAdapter extends RecyclerView.Adapter<RecruitAdapter.Holder> {

    private OnItemClick onItemClick;
    private Context context;
    private List<RecruitBean> list;
    public RecruitAdapter(Context context,List<RecruitBean> list){
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public RecruitAdapter.Holder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new Holder(LayoutInflater.from(context).inflate(R.layout.recruit_item_layout,parent,false));
    }

    @Override
    public void onBindViewHolder(@NonNull RecruitAdapter.Holder holder, @SuppressLint("RecyclerView") int position) {
        holder.itemBinding.name.setText(list.get(position).getName());
        holder.itemBinding.introduce.setText(list.get(position).getIntroduce());
        Glide.with(context).load(list.get(position).getBg()).into(holder.itemBinding.image);
        holder.itemBinding.cardView1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onItemClick.onClick(position);
            }
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public class Holder extends RecyclerView.ViewHolder {
        private RecruitItemLayoutBinding itemBinding;

        public Holder(@NonNull View itemView) {
            super(itemView);
            itemBinding = RecruitItemLayoutBinding.bind(itemView);
        }
    }

    public void setOnItemClick(OnItemClick onItemClick){
        this.onItemClick = onItemClick;

    }

    public interface OnItemClick{
        void onClick(int position);
    }
}
